#pragma once
#include "Base\AbstractRemoteProcedure.h"
#include <QObject>
#include "Network/Connection.h"
#include "Data\User.h"

namespace TC
{
	namespace Request
	{
		class TCCORE_EXPORT TeachersFetcher : public AbstractRemoteProcedure
		{
			Q_OBJECT
				Q_PROPERTY(QVariantList groups MEMBER groups)
		public:
			Q_INVOKABLE void fetch(quint64 groupId, quint64 idBegin, quint64 idEnd)
			{
				if (status() == Status::Communicating)
					return;
				AbstractRemoteProcedure::get("evaluation/p2p/teachers/fetch",
				{
					{ "signature", Data::User::instance()->signature() },
					{ "groupId", groupId },
					{ "idBegin", idBegin },
					{ "idEnd", idEnd },
				});
			}
		protected:
			void onDataReady(QDataStream &stream) override
			{
				bool result;
				stream >> result;
				if (result)
				{
					QList<QVariantMap> vms;
					stream >> vms;
					groups.clear();
					for (QVariantMap &v : vms)
					{
						groups.append(v);
					}
					setOk();
				}
				else
				{
					setFailed();
				}
			}
		private:
			QList<QVariant> groups;
		};
	}
}